package com.rj.framework.component.tech.captcha;

import lombok.Data;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
     * 验证码记录
     */
    @Data
    public  class CaptchaRecord {
        private final String id;           // 唯一ID
        private final String code;         // 验证码
        private final CaptchaType type;    // 类型
        private final String target;       // 目标地址
        private final LocalDateTime createTime; // 创建时间
        private final LocalDateTime expireTime; // 过期时间
        private final Map<String, String> clientInfo; // 客户端信息
        
        private int attempts;              // 尝试次数
        
        public CaptchaRecord(String id, String code, CaptchaType type, String target,
                             LocalDateTime createTime, LocalDateTime expireTime,
                             Map<String, String> clientInfo) {
            this.id = id;
            this.code = code;
            this.type = type;
            this.target = target;
            this.createTime = createTime;
            this.expireTime = expireTime;
            this.clientInfo = clientInfo != null ? clientInfo : new HashMap<>();
            this.attempts = 0;
        }
        
        public boolean isExpired() {
            return LocalDateTime.now().isAfter(expireTime);
        }
        
        public void incrementAttempts() {
            attempts++;
        }
    }